import configparser

import yaml
from yaml import Loader, Dumper


class SysConfig(object):
    config_file = "./sys_config.ini"
    config = configparser.ConfigParser()
    config.read([config_file], encoding="utf-8")
    PYTHON_BIN = config.get("PYTHON_ENV", "PYTHON_BIN", fallback="/usr/bin/python")
    GRPC_MAIN_PORT = config.getint("GRPC", "GRPC_MAIN_PORT", fallback=10052)


class SysConfig2(object):
    config_file = "./yolov3-spp.yaml"
    with open(config_file, 'r', encoding='utf8') as fr:
        config = yaml.load(fr, Loader)

    @classmethod
    def dump_demo(cls):
        obj1 = {"obj1": [{'name': 'bob', 'age': 19}, {'name': 20, 'age': 23}, {'name': 'leo', 'age': 25}]}
        obj2 = {"obj2": [{'name': 'bob', 'age': 26}, {'name': 34, 'age': 67}, {'name': 'leo', 'age': 89}]}
        with open("test.yaml", 'w', encoding='utf8') as fw:
            yaml.dump_all([obj1, obj2], fw)

        with open("test.yaml", 'r', encoding='utf8') as fr:
            return list(yaml.load_all(fr, Loader))





if __name__ == '__main__':
    print(SysConfig.PYTHON_BIN)
    print(SysConfig.GRPC_MAIN_PORT)
    print(SysConfig2.config)
    print(SysConfig2.dump_demo())
